package com.lmabbe.tenant.service.impls;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmabbe.tenant.mapper.TenantInfoMapper;
import com.lmabbe.tenant.objects.dto.TenantRenewalDTO;
import com.lmabbe.tenant.objects.entity.TenantInfo;
import com.lmabbe.tenant.service.TenantInfoService;
import org.springframework.stereotype.Service;

/**
 * @author lmabbe
 * @data 2021/3/13 17:00
 */
@Service
public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantInfo> implements TenantInfoService {
    @Override
    public TenantInfo findByCode(String code) {
        return this.baseMapper.selectOne(new QueryWrapper<TenantInfo>().lambda().eq(TenantInfo::getTenantCode, code));
    }

    @Override
    public boolean existsCode(String code) {
        return findByCode(code) != null;
    }

    @Override
    public void renewal(Long tenantId, TenantRenewalDTO tenantRenewalDTO) {
        TenantInfo tenantInfo = new TenantInfo();
        tenantInfo.setTenantId(tenantId);
        tenantInfo.setOverdueTime(DateUtil.parseDateTime(tenantRenewalDTO.getOverdueTime()));
        this.baseMapper.updateById(tenantInfo);
    }
}
